*******************************************************************************************
* Tables 
*******************************************************************************************

****Prelim

set scheme  s1mono, perm

clear all
set matsize 5000

cd C:\Dropbox\Spillover_Package
cd proc


*************************************************************************************
***  Figures
*************************************************************************************
{
*****************************************************************
* Figure 1: Number of patents and citations per patent in the raw data
*****************************************************************
{
* Subfigure a) # of Patents and Citations per Patent
{
use patentRaw_aggregated, clear
twoway (line patentCount appyear, lpattern(dash_dot) lcolor(edkblue) lwidth(thick)) (line forwardCites appyear, yaxis(2) lcolor(edkblue) lwidth(thick)), legend(order (2 "Average Citations" 1 "Total Number of Patents")) xtitle(Application Year)  xline(1997 2002)  xlabel(1975(5)2010)
}
* Subfigure b)  # of Start-ups and Share with Patent
{
use ventureDescriptive_aggregated, clear
twoway (line fundingRoundNumber year, lcolor(edkblue) lwidth(thick)) (line share year, yaxis(2)  lpattern(dash_dot) lcolor(edkblue) lwidth(thick)), xline(1979) legend(order (1 "# of Start-ups" 2 "% with Patent")) xtitle (Year of first investment)
}
* Subfigure c)  Average Scaled Citations per Patent over Time
{
use work_aggregated, clear
sort venture appyear
twoway (connected forwardCites_scaled_base appyear if venture==1 , color(edkblue) lwidth(thick) lpattern( solid ))   (connected forwardCites_scaled_base appyear if venture==0, color(edkblue) lwidth(thick)  lpattern( dash_dot ) )  , ytitle("Scaled Citations")  xtitle("Application Year") legend( lab(1  "Patents of start-ups") lab(2 "Patents of est. companies"))
}

}

*******************************************************************
* Figure 2: Citation patterns of technology classes 
*******************************************************************
{
* Preparations
{
use nclassNclassLikelihood, clear
set matsize 11000
keep if appyear==2000
merge m:1 nclass using  patentCategory 
keep subcat nclassOrg oneSumBasic oneSumAbsolut
ren nclassOrg nclass
ren subcat subcatTo
merge m:1 nclass using  patentCategory
keep subcat subcatTo oneSumAbsolut // Convert nclass to tech classes
collapse (sum) oneSumAbsolut, by(subcat subcatTo)
foreach x in subcat subcatTo {
drop if `x' == 19 | `x' == 25 | `x' == 49 | `x' == 69 | `x' == 59 | `x' == 39 
drop if `x'>59
}
drop if subcatTo==.
drop if subcat==.
replace oneSumAbsolut=0 if oneSumAbsolut==.
bysort subcatTo: egen summer = sum(oneSumAbsolut) // Every subcatTo to has a vote, share of 
replace oneSumAbsolut = oneSumAbsolut/summer
ren oneSumAbsolut  n
drop  summer
* oneSum: Share of cites nclassOrg gives to nclass
* oneSumBasic: Share of cites nclass draws from nclass Org
* oneSum Absolut: All cites nclassOrg gives to all nclasses
save heatfile1, replace
}

* Subfigure a) Cross citation matrix
{
use heatfile1, clear
replace n = n *100
reshape wide n, i(subcatTo) j( subcat)

drop subcatTo
mkmat n*, matrix(Y) 

* Categorization is according to NBER lessons learned document p.41.
* To arrive at nicer labels: Change labels with the Graph editor 
matrix rownames Y = Agriculture	Coating	Gas	Organic_Compounds	Resins	Communication	Computer_Hardware	Computer_Peripherals Information_Storage 	Drugs	Medical_Instruments	Biotech		Electrical_Devices	Electrical_Lightning	Measuring	Nuclear	Power_Systems	Semiconductor		Material	Metal_Working	Motors Optics	Transport	
matrix colnames Y = Agriculture	Coating	Gas	Organic_Compounds	Resins	Communication	Computer_Hardware	Computer_Peripherals Information_Storage 	Drugs	Medical_Instruments	Biotech		Electrical_Devices	Electrical_Lightning	Measuring	Nuclear	Power_Systems	Semiconductor		Material	Metal_Working	Motors Optics	Transport	
plotmatrix, m(Y)    maxticks(100) ylabel(,angle(0) labsize(small)  ) xlabel(,angle(90) labsize(small)) split(0.1 1 5 10 25 50 75 90 100) legend(pos(1) cols(2) rows(6) ring(0) symysize(3) symxsize(3) textwidth(6) size(vsmall))
}

* Subfigure b) Share of Cites from other technological subcategories
{
use heatfile1, clear
keep if subcat == subcatTo
scatter n subcat 

sort subcat
gen number = _n
replace n = 1-n
replace n = floor(n*10000)/100
format %9.0f n
label var n "Citations from other subcategories in %"
label var number "Technological subcategory"

scatter  n number , color(edkblue) yscale(range(0 70)) ylabel(0(10)70) mlabel(n) xtitle("")  mlabpos(12) xlabel(1 "Agriculture"	2 "Coating"	3 "Gas"	4 "Organic Compounds" 5	"Resins" 6	"Communication"	7 "Computer Hardware"	8 "Computer Peripherals" 9 "Information Storage"  10	"Drugs" 11	"Medical Instruments" 12	"Biotech"	13	"Electrical Devices"	14 "Electrical Lightning" 15	"Measuring" 16	"Nuclear"	17 "Power Systems" 18	"Semiconductors"	19	"Material"	20 "Metal Working" 21	"Motors" 22 "Optics" 23	"Transport"	, angle(vertical)) ytitle(, size(small))
}


* Subfigure c) Citations of Computer Hardware and Software
{
use heatfile1, clear
keep if subcatTo==22
drop if n<0.0145
sort n
 
gen number = _n
replace n = floor(n*10000)/100
format %9.2f n
label var number "Technological subcategory"
gen nlabel = string(n, "%8.0f") + "%"
twoway (scatter n number [aweight=n],  yscale(off) yscale(log) xtitle("") msymbol(circle_hollow) color(edkblue) xlabel( 1	"Measuring" 2 "Computer Peripherials" 3 "Information Storage"	 4 "Communications" 5 "Computer Hardware", angle(vertical) 	)) (scatter n number, mlabel(nlabel) msymbol(none)  mlabgap(3)  yscale(range(1 150)) xscale(range(1 5.5))), legend(off) 
}

}





************************************************************************************
* Figure 3: Mechanism: Spillovers of Venture Capital onto established companies
************************************************************************************
{
* Subfigure a) Quality of ideas
{
eststo clear
use work, clear

local i = 0
gen VentureSpill=0
gen EstablishedSpill = 0
gen IV1 = 0 
gen IV2 = 0
local direct cumRD

replace EstablishedSpill =  C_cumRD
replace VentureSpill = C_AmountCum

replace IV1 = C_cumRD_p
replace IV2 = C_AmountCum_p

gen b1 = .
gen b2 = .
gen se1= .
gen se2=.
gen counter = .
gen name = ""
local i = 1
global exogenous preSample dum_preSample   
eststo r2: xi:  ivreg  forwardCites_scaled i.SIC i.year   (VentureSpill EstablishedSpill =IV1 IV2 )    cumRD     $exogenous     if venture==0 , cluster(SIC)   
replace b1 = _b[VentureSpill] in `i'
replace se1 = _se[VentureSpill] in `i'

replace counter = `i' in `i'
replace name = "`x'" in `i'
local i = `i'+1



foreach x in  forwardCites_scaled_pP generality_scaled_pP originality_scaled_pP     { 
xi:  ivreg  forwardCites_scaled i.SIC i.year   (EstablishedSpill C_AC_`x'_1 C_AC_`x'_2=IV1 C_AC_`x'_1_p C_AC_`x'_2_p )   cumRD   $exogenous   if venture==0  , cluster(SIC) 

replace b1 = _b[ C_AC_`x'_1] in `i'
replace se1 = _se[  C_AC_`x'_1] in `i'
replace b2 = _b[ C_AC_`x'_2] in `i'
replace se2 = _se[  C_AC_`x'_2] in `i'

replace counter = `i' in `i'
replace name = "`x'" in `i'
local i = `i'+1

}

foreach x in g_pat_ab g_pat_75_ab i_pat_ab    { 
xi:  ivreg  forwardCites_scaled i.SIC i.year   (EstablishedSpill C_AC_`x'_1 C_AC_`x'_2=IV1 C_AC_`x'_1_p C_AC_`x'_2_p )   cumRD   $exogenous   if venture==0  , cluster(SIC) 

replace b1 = _b[ C_AC_`x'_1] in `i'
replace se1 = _se[  C_AC_`x'_1] in `i'
replace b2 = _b[ C_AC_`x'_2] in `i'
replace se2 = _se[  C_AC_`x'_2] in `i'

replace counter = `i' in `i'
replace name = "`x'" in `i'
local i = `i'+1
}

xi:  ivreg  forwardCites_scaled i.SIC i.year   (EstablishedSpill C_AC_gi_75_ab_0_0 C_AC_gi_75_ab_0_1 C_AC_gi_75_ab_1_0 C_AC_gi_75_ab_1_1=IV1  C_AC_gi_75_ab_0_0_p C_AC_gi_75_ab_0_1_p C_AC_gi_75_ab_1_0_p C_AC_gi_75_ab_1_1_p)   cumRD   $exogenous   if venture==0 , cluster(SIC) 

cap replace b1 = _b[ C_AC_gi_75_ab_0_0] in `i'
cap replace se1 = _se[  C_AC_gi_75_ab_0_0] in `i'
cap replace b2 = _b[ C_AC_gi_75_ab_0_1] in `i'
cap replace se2 = _se[ C_AC_gi_75_ab_0_1] in `i'

cap replace counter = `i' in `i'
cap replace name = "gi_ab_not_novel" in `i'
cap local i = `i'+1

xi:  ivreg  forwardCites_scaled i.SIC i.year   (EstablishedSpill C_AC_gi_75_ab_0_0 C_AC_gi_75_ab_0_1 C_AC_gi_75_ab_1_0 C_AC_gi_75_ab_1_1=IV1  C_AC_gi_75_ab_0_0_p C_AC_gi_75_ab_0_1_p C_AC_gi_75_ab_1_0_p C_AC_gi_75_ab_1_1_p)   cumRD   $exogenous   if venture==0 , cluster(SIC) 

cap replace b1 = _b[ C_AC_gi_75_ab_1_0] in `i'
cap replace se1 = _se[  C_AC_gi_75_ab_1_0] in `i'
cap replace b2 = _b[ C_AC_gi_75_ab_1_1] in `i'
cap replace se2 = _se[ C_AC_gi_75_ab_1_1] in `i'

cap replace counter = `i' in `i'
cap replace name = "gi_75_ab_novel" in `i'
cap local i = `i'+1

keep if counter!=.
keep b? se? counter name 
gen upper1 = b1 + 1.645*se1
gen lower1 = b1 - 1.645*se1
gen upper2 = b2 + 1.645*se2
gen lower2 = b2 - 1.645*se2


gen counter1 = (counter*-1)+6
gen counter2 = counter+0.5
drop counter

gen significant1 = upper1<0 | lower1>0
gen significant2 = upper2<0 | lower2>0
gen id = _n
reshape long b se upper lower counter significant, i(id) j(change)
drop change
drop counter 
drop if b ==.
gen counter = _n 

replace counter = 18-counter
replace counter = counter-1.5 if counter<16
replace counter = counter-0.5 if counter<13.5
replace counter = counter-0.5 if counter<11
replace counter = counter-1.5 if counter<8.5
replace counter = counter-0.5 if counter<5
replace counter = counter-0.5 if counter<2.5
replace counter = counter-0.5 if counter<0

replace counter = counter+3
replace counter = 17.5 if counter==19

replace counter = counter/2

twoway (rcap upper lower counter, horizontal color(gs10)) (scatter counter b if significant==0, color(edkblue) msymbol(oh) msize(large))  (scatter counter b if significant==1, color(red) msymbol(d) msize(large)) , ytitle("") ysize(6.5) legend(off) xline(0)   ylabel(10 "- (1) Baseline                                                        "  9.25 "- Start-ups where the average patents has...     " 8.75 " (2) citations below median" 8.25 "citations above median"  7.5 "(3) generality < median" 7 "generality > median" 6.25 "(4) originality < median" 5.75 "originality > median"   5 "- Start-ups with first patents with...                "  4.5 "(5) text novelty of first patent < median" 4 "text novelty of first patent > median" 3.25 "(6) text novelty of first patent < 75th pctl" 2.75 "text novelty of first patent > 75th pctl" 2 "(7) # figures of first patent < median" 1.5 "# figures of first patent > median" 0.75 "(8) novelty < 75th pctl & # figures < median" 0.25 "novelty < 75th pctl & # figures > median" -0.25 "novelty > 75th pctl & # figures < median" -0.75 "novelty > 75th pctl & # figures > median",  valuelabel labsize(small) angle(0) ) scale(1.2) xlabel(-20(10)30) xscale(range(-15 15)) xlabel(,labsize(2))
}


* Subfigure b) Strength of patent protection
{
eststo clear
use work, clear


local i = 0
gen VentureSpill=0
gen EstablishedSpill = 0
gen IV1 = 0 
gen IV2 = 0
local direct cumRD

global exogenous      preSample dum_preSample    



replace EstablishedSpill =  C_cumRD
replace VentureSpill = C_AmountCum

replace IV1 = C_cumRD_p
replace IV2 = C_AmountCum_p

gen b1 = .
gen b2 = .
gen se1= .
gen se2=.
gen counter = .
gen name = ""
local i = 1

eststo r2: xi:  ivreg  forwardCites_scaled i.SIC i.year   (VentureSpill EstablishedSpill =IV1 IV2 )    cumRD   $exogenous   if venture==0 , cluster(SIC)   
replace b1 = _b[VentureSpill] in `i'
replace se1 = _se[VentureSpill] in `i'

replace counter = `i' in `i'
replace name = "`x'" in `i'
local i = `i'+1

eststo r2: xi:  ivreg  forwardCites_scaled i.SIC i.year   (VentureSpill EstablishedSpill =IV1 IV2 )    cumRD   $exogenous   if venture==0 & mComp<0.5 , cluster(SIC)   
replace b1 = _b[VentureSpill] in `i'
replace se1 = _se[VentureSpill] in `i'

replace counter = `i' in `i'
replace name = "`x'" in `i'
local i = `i'+1


eststo r2: xi:  ivreg  forwardCites_scaled i.SIC i.year   (VentureSpill EstablishedSpill =IV1 IV2 )    cumRD   $exogenous   if venture==0 & mComp>=0.5 , cluster(SIC)   
replace b1 = _b[VentureSpill] in `i'
replace se1 = _se[VentureSpill] in `i'

replace counter = `i' in `i'
replace name = "`x'" in `i'
local i = `i'+1


foreach x in complexity w_pat_ab  lf_claim_res_min    { 
xi:  ivreg  forwardCites_scaled i.SIC i.year   (EstablishedSpill C_AC_`x'_1 C_AC_`x'_2=IV1 C_AC_`x'_1_p C_AC_`x'_2_p )   cumRD   $exogenous   if venture==0  , cluster(SIC) 

replace b1 = _b[ C_AC_`x'_1] in `i'
replace se1 = _se[  C_AC_`x'_1] in `i'
replace b2 = _b[ C_AC_`x'_2] in `i'
replace se2 = _se[  C_AC_`x'_2] in `i'

replace counter = `i' in `i'
replace name = "`x'" in `i'
local i = `i'+1
}



keep if counter!=.
keep b? se? counter name 
gen upper1 = b1 + 1.645*se1
gen lower1 = b1 - 1.645*se1
gen upper2 = b2 + 1.645*se2
gen lower2 = b2 - 1.645*se2


gen counter1 = (counter*-1)+6
gen counter2 = counter+0.5
drop counter

gen significant1 = upper1<0 | lower1>0
gen significant2 = upper2<0 | lower2>0
gen id = _n
reshape long b se upper lower counter significant, i(id) j(change)
drop change
drop counter 
drop if b == .
gen counter = _n 
replace counter = 10-counter
replace counter = counter-1.5 if counter<9
replace counter = counter-1.5 if counter<5.5
replace counter = counter-0.5 if counter<2
replace counter = counter-0.5 if counter<-0.5

replace counter = counter+4



replace counter = counter/2
twoway (rcap upper lower counter, horizontal color(gs10)) (scatter counter b if significant==0, color(edkblue) msymbol(oh) msize(large))  (scatter counter b if significant==1, color(red) msymbol(d) msize(large)) , ytitle("") ysize(5) legend(off) xline(0)  ylabel(6.5 "-(1) Baseline                                                               "  5.75 "- Spillovers onto established companies...            "  5.25 "(2) in discrete product industries" 4.75 "(3) complex product industries"  4 "- Spillovers from start-ups...                                   " 3.5 "(4) in discrete product industries" 3 "in complex product industries" 2.25 "(5) with patent scope of first patent > median" 1.75 "with patent scope of first patent < median"  1 "(6) max patent scope > median " 0.5 "max patent scope < median"  ,  valuelabel labsize(small) angle(0) )  scale(1.2) xlabel(-20(10)20) xscale(range(-15 15)) xlabel(,labsize(2.5)) 
}



* Subfigure c) Movement
{
eststo clear
use work, clear



local i = 0
gen VentureSpill=0
gen EstablishedSpill = 0
gen IV1 = 0 
gen IV2 = 0
local direct cumRD

global exogenous      preSample dum_preSample    
replace EstablishedSpill =  C_cumRD
replace VentureSpill = C_AmountCum

replace IV1 = C_cumRD_p
replace IV2 = C_AmountCum_p

gen b1 = .
gen b2 = .
gen se1= .
gen se2=.
gen counter = .
gen name = ""
local i = 1

eststo r2: xi:  ivreg  forwardCites_scaled i.SIC i.year   (VentureSpill EstablishedSpill =IV1 IV2 )    cumRD   $exogenous   if venture==0 , cluster(SIC)   
replace b1 = _b[VentureSpill] in `i'
replace se1 = _se[VentureSpill] in `i'

replace counter = `i' in `i'
replace name = "`x'" in `i'
local i = `i'+1



foreach x in  firstTime     { 
xi:  ivreg  forwardCites_scaled i.SIC i.year   (EstablishedSpill C_AC_inv_`x'_1 C_AC_inv_`x'_2=IV1 C_AC_inv_`x'_1_p C_AC_inv_`x'_2_p )   cumRD   $exogenous   if venture==0 , cluster(SIC) 

replace b1 = _b[ C_AC_inv_`x'_2] in `i'
replace se1 = _se[  C_AC_inv_`x'_2] in `i'
replace b2 = _b[ C_AC_inv_`x'_1] in `i'
replace se2 = _se[  C_AC_inv_`x'_1] in `i'

replace counter = `i' in `i'
replace name = "`x'" in `i'
local i = `i'+1
}



eststo r2: xi:  ivreg  forwardCites_scaled i.SIC i.year   ( EstablishedSpill C_AmountCum_High C_AmountCum_Low  = C_cumRD_p C_AmountCum_High_p  C_AmountCum_Low_p)     cumRD   $exogenous   if venture==0 , cluster(SIC)   

replace b1 = _b[ C_AmountCum_Low] in `i'
replace se1 = _se[ C_AmountCum_Low] in `i'
replace b2 = _b[ C_AmountCum_High] in `i'
replace se2 = _se[  C_AmountCum_High] in `i'

replace counter = `i' in `i'
replace name = "`x'" in `i'
local i = `i'+1



global endog (EstablishedSpill  C_AC_pat_firstTime_0_1 C_AC_pat_firstTime_1_1 C_AC_pat_firstTime_0_0 C_AC_pat_firstTime_1_0 =IV1 C_AC_pat_firstTime_0_0_p C_AC_pat_firstTime_0_1_p   C_AC_pat_firstTime_1_0_p  C_AC_pat_firstTime_1_1_p  )

xi:  ivreg  forwardCites_scaled i.SIC i.year   $endog   cumRD   $exogenous   if venture==0 , cluster(SIC) 

replace b1 = _b[C_AC_pat_firstTime_0_1] in `i'
replace se1 = _se[C_AC_pat_firstTime_0_1] in `i'
replace b2 = _b[C_AC_pat_firstTime_1_1] in `i'
replace se2 = _se[ C_AC_pat_firstTime_1_1] in `i'
replace counter = `i' in `i'
replace name = "experience x patent" in `i'
local i = `i'+1

replace b1 = _b[C_AC_pat_firstTime_0_0] in `i'
replace se1 = _se[C_AC_pat_firstTime_0_0] in `i'
replace b2 = _b[C_AC_pat_firstTime_1_0] in `i'
replace se2 = _se[ C_AC_pat_firstTime_1_0] in `i'
replace counter = `i' in `i'
replace name = "experience x patent" in `i'
local i = `i'+1



foreach x in  festablished     { 
xi:  ivreg  forwardCites_scaled i.SIC i.year   (EstablishedSpill C_AC_inv_`x'_1 C_AC_inv_`x'_2=IV1 C_AC_inv_`x'_1_p C_AC_inv_`x'_2_p )    cumRD   $exogenous   if venture==0, cluster(SIC) 

replace b1 = _b[ C_AC_inv_`x'_1] in `i'
replace se1 = _se[  C_AC_inv_`x'_1] in `i'
replace b2 = _b[ C_AC_inv_`x'_2] in `i'
replace se2 = _se[  C_AC_inv_`x'_2] in `i'

replace counter = `i' in `i'
replace name = "`x'" in `i'
local i = `i'+1
}


global endog (EstablishedSpill C_AC_festablished_0_0  C_AC_festablished_0_1  C_AC_festablished_1_0 C_AC_festablished_1_1  = IV1 C_AC_festablished_0_0_p  C_AC_festablished_0_1_p C_AC_festablished_1_0_p C_AC_festablished_1_1_p)

xi:  ivreg  forwardCites_scaled i.SIC i.year   $endog   cumRD   $exogenous   if venture==0 , cluster(SIC) 
replace b1 = _b[C_AC_festablished_0_0] in `i'
replace se1 = _se[C_AC_festablished_0_0] in `i'
replace b2 = _b[ C_AC_festablished_0_1] in `i'
replace se2 = _se[ C_AC_festablished_0_1] in `i'
replace counter = `i' in `i'
replace name = "total x quality" in `i'
local i = `i'+1

replace b1 = _b[ C_AC_festablished_1_0] in `i'
replace se1 = _se[ C_AC_festablished_1_0] in `i'
replace b2 = _b[C_AC_festablished_1_1] in `i'
replace se2 = _se[C_AC_festablished_1_1] in `i'

replace counter = `i' in `i'
replace name = "total x quality" in `i'
local i = `i'+1


sum C_AC_prox_1, d
replace C_AC_prox_1 = r(p99) if C_AC_prox_1 >r(p99)
sum C_AC_prox_2, d
replace C_AC_prox_2 = r(p99) if C_AC_prox_2 >r(p99)


foreach x in      prox  prox_bi    { 
xi:  ivreg  forwardCites_scaled i.SIC i.year   (EstablishedSpill C_AC_`x'_1 C_AC_`x'_2=IV1 C_AC_`x'_1_p C_AC_`x'_2_p )   cumRD   $exogenous   if venture==0 , cluster(SIC) 

cap replace b1 = _b[ C_AC_`x'_1] in `i'
cap replace se1 = _se[  C_AC_`x'_1] in `i'
cap replace b2 = _b[ C_AC_`x'_2] in `i'
cap replace se2 = _se[  C_AC_`x'_2] in `i'

cap replace counter = `i' in `i'
cap replace name = "`x'" in `i'
cap local i = `i'+1
}






keep if counter!=.
keep b? se? counter name 
gen upper1 = b1 + 1.645*se1
gen lower1 = b1 - 1.645*se1
gen upper2 = b2 + 1.645*se2
gen lower2 = b2 - 1.645*se2


gen counter1 = (counter*-1)+6
gen counter2 = counter+0.5
drop counter

gen significant1 = upper1<0 | lower1>0
gen significant2 = upper2<0 | lower2>0
gen id = _n
reshape long b se upper lower counter significant, i(id) j(change)
drop change
drop counter 
drop if b == .
gen counter = _n 
replace counter = 20-counter
replace counter = counter-1.5 if counter<19
replace counter = counter-0.5 if counter<15.5
replace counter = counter-0.5 if counter<13

replace counter = counter-1.5 if counter<8.5
replace counter = counter-0.5 if counter<5
replace counter = counter-1.5 if counter<0.5

replace counter = counter-0.5 if counter<-3


drop if counter<19& counter>=8.5
replace counter = 8.5 if counter==19
replace counter = counter/2
twoway (rcap upper lower counter, horizontal color(gs10)) (scatter counter b if significant==0, color(edkblue) msymbol(oh) msize(large))  (scatter counter b if significant==1, color(red) msymbol(d) msize(large)) , ytitle("") ysize(5) legend(off) xline(0)    ylabel(4.25 "- (1) Baseline                                                     "   3.5 "- Future patents for established: Start-ups..." 3 "(2) with inventors with no future patents" 2.5 "with inventors with future patents" 1.75 "(3) no future patents & not novel" 1.25 "no future patents & novel" 0.75 "future patenting & not novel" 0.25 "future patenting & novel" -0.5 "- Network measures: Start-ups with...         " -1 "(4) low labor mobility" -1.5 "high labor mobility" -2.25 "(5) sparse co-author network" -2.75 "dense co-author network" ,  valuelabel labsize(small) angle(0) ) scale(1.2) xlabel(-10(10)20) xscale(range(-15 15)) xlabel(,labsize(2.5))

}




}



}

*************************************************************************************
***  Tables
*************************************************************************************
{

****************************************************************************
* Table 1: Summary statistics
****************************************************************************
{
* Panel A: Established companies
{
use work, clear


keep if established==1

global characteristics   patentCount_base forwardCites_base forwardCites_scaled_base mComp weightCites
replace sale = sale/1000

label var forwardCites_base "Citation-weighted patents p.a."
label var forwardCites_scaled_base "Scaled citation-weighted patents p.a."
label var year "Years in the data"
label var patentCount_base "Patent count (per annum)"
label var year "Number of Years in Data"
label var xrd_base "Average R\&D (million dollars)"
label var sale "Average sales (billion dollars)"
label var mComp "Average complexity of companies' patents"
label var weightCites "Average citation-augmented proximity (x 100)"

bysort gvkey: egen inData = sum(1)
bysort gvkey: egen minimumYear = min(year)
replace inData=. if year!=minimumYear
label var inData "Years in data"

eststo stats: estpost summarize   $characteristics  xrd_base sale  inData, detail
esttab stats,noobs  nolines fragment cells("mean(fmt(%9.2f)) sd(fmt(%9.2f)) min(fmt(%9.0f)) max(fmt(%9.0f)) p10(fmt(%9.0f)) p90(fmt(%9.0f))")  nomtitle nonumber label compress replace nodepvars
}



* Panel B: Venture Capital-backed Start-ups
{
use work, clear



keep if venture == 1

drop if year<firstInvestment

global characteristics   patentCount_base forwardCites_base forwardCites_scaled_base mComp weightCites 


label var forwardCites_base "Citation-weighted patents p.a."
label var forwardCites_scaled_base "Scaled citation-weighted patents p.a."
label var year "Years in the data"
label var patentCount_base "Patent count (per annum)"
label var Amount "Total VC investment (million dollars)"
label var mComp "Average complexity of companies' patents"
label var weightCites "Average citation-augmented proximity (x 100)"


bysort ID: egen inData = sum(1)
replace inData = . if year!=firstInvestment
label var inData "Years in data"

eststo stats: estpost summarize  $characteristics Amount inData, detail
esttab stats ,  fragment nolines noobs cells("mean(fmt(%9.2f)) sd(fmt(%9.2f)) min(fmt(%9.0f)) max(fmt(%9.0f)) p10(fmt(%9.0f)) p90(fmt(%9.0f))")  nomtitle nonumber label compress replace 



}
}
****************************************************************************
* Table 2: Summary statistics of VC and Established Patents
****************************************************************************
{
use work,clear

global characteristics  

global characteristics   forwardCites_base forwardCites_scaled_base generality_base generality_scaled_base originality_base originality_scaled_base  above_base outstanding_base 




collapse (sum) Amount xrd_base patentCount_base $characteristics, by(gvkey ID established)
label var patentCount_base "\# patents"
label var above_base "I(Best 50\% of citations)"
label var outstanding_base    "I(Best 5\% of citations)"
label var forwardCites_base  "Forward citations"
label var forwardCites_scaled_base "Scaled citations"
label var generality_base  "Generality"
label var generality_scaled_base  "Scaled generality"
label var originality_base  "Originality"
label var originality_scaled_base  "Scaled originality"
preserve
replace xrd_base = 0 if xrd_base==.
replace Amount=0 if Amount==.
foreach x in patentCount_base $characteristics {
replace `x' = `x'/(Amount+xrd_base+1)
}

eststo r1: estpost ttest  $characteristics patentCount_base, by(established) unequal
restore
foreach x in $characteristics {
replace `x' = `x'/(patentCount_base+1)
}
eststo r2: estpost ttest   $characteristics, by(established) unequal

* Per patents
esttab r2 , /// 
	cells("mu_2(fmt(%9.2f) label(Established)) mu_1(fmt(%9.2f) label(Venture)) b(fmt(%9.2f) label(Diff)) p(fmt(%9.2f) label(P-Value))") ///
	fragment booktabs nodepvar noobs nomtitle nonumbers label star(* 0.10 ** 0.05 *** 0.01) staraux  replace
* Per Dollar
	esttab r1, /// 
	cells("mu_2(fmt(%9.2f) label(Established)) mu_1(fmt(%9.2f) label(Venture)) b(fmt(%9.2f) label(Diff)) p(fmt(%9.2f) label(P-Value))") ///
	fragment booktabs nodepvar noobs nomtitle nonumbers label star(* 0.10 ** 0.05 *** 0.01) staraux  replace

}

*****************************************************************************
* Table 3: Regression of VC and R&D expenditure on instruments
*****************************************************************************
{


use work, clear

local i = 1
replace Amount = ln(Amount)
foreach x in FundVenture FundSizeUSDMilRaw FundSizeUSDMil    FundSize  {
replace `x' = ln(`x')/100
eststo r`i': reg Amount i.SIC i.year `x' pre1978SforwardCites_scaled  if  venture==1 &Amount>0, cluster(SIC) 
test(`x')
estadd scalar fvalue = r(F)
local i = `i'+1
}

eststo r`i': reg Amount i.SIC i.year FundSizeUSDMilRaw FundSizeUSDMil    FundSize pre1978SforwardCites_scaled  if  venture==1, cluster(SIC) 
test(FundSizeUSDMilRaw FundSizeUSDMil   FundSize)
estadd scalar fvalue = r(F)
local i = `i'+1


label var FundVenture "VC Fundraising"

*replace rdCosts= ln(rdCosts+1)
eststo r`i': reg xrd i.SIC i.year rdCosts pre1978SforwardCites_scaled lnSale if  venture==0 & xrd>0, cluster(SIC) 
test(rdCosts)
estadd scalar fvalue = r(F)
local i = `i'+1
label var rdCosts "R\&D Costs"
estout r1 r2 r3 r4  r6  , cells(b(fmt(%9.2f) star) se(fmt(%9.2f) par)) stats(fvalue r2 N, labels("F-Value"  "R2" "N") fmt(2 2 0))   label varlabels(_cons Constant)  collabels(none) substitute(_ \_ "\_cons " \_cons)  level(95)  keep(FundVenture FundSizeUSDMilRaw FundSizeUSDMil    FundSize rdCosts) order( FundVenture FundSizeUSDMilRaw FundSizeUSDMil  FundSize  rdCosts)


}


************************************************************************************
* Table 4 & Table 5: : Measurement of Spillovers - Established Companies / Start-ups
************************************************************************************
{


eststo clear
use work, clear


local i = 0
gen VentureSpill=0
gen EstablishedSpill = 0
gen IV1 = 0 
gen IV2 = 0
local direct cumRD
global exogenous      
forvalues k = 0/1 {
forvalues i = 1/3 {

di `i' " " `k'


if `i'==1 {
replace EstablishedSpill =  J_cumRD
replace VentureSpill = J_AmountCum
replace IV1 = J_cumRD_p
replace IV2 = J_AmountCum_p
}
else if `i'==2 {
replace EstablishedSpill =  C_cumRD
replace VentureSpill = C_AmountCum

replace IV1 = C_cumRD_p
replace IV2 = C_AmountCum_p
}
else if `i'==3 {
replace EstablishedSpill =  w12_cumRD
replace VentureSpill = w12_AmountCum
replace IV1 = w12_cumRD_p
replace IV2 = w12_AmountCum_p
}
eststo r`i'`k'1: xi: ivreg2 forwardCites_scaled i.year i.SIC   EstablishedSpill VentureSpill `direct'   preSample dum_preSample      if venture==`k' ,  cluster(SIC)    partial(i.SIC i.year)
estadd scalar fvalue = .
estadd local patentClass "Yes"
estadd local yearFix "Yes"


eststo r`i'`k'2: xi:  ivreg2  forwardCites_scaled i.SIC i.year   (VentureSpill EstablishedSpill =IV1 IV2 )    `direct'    preSample dum_preSample      if venture==`k' , cluster(SIC)   partial(i.SIC i.year) 
estadd scalar fvalue = e(F)
estadd local patentClass "Yes"
estadd local yearFix "Yes"


} 
local direct AmountCum
}

label var EstablishedSpill "Ln(Spillover Est.)" 
label var  VentureSpill "Ln(Spillover VC.)"


* Established companies
estout  r301 r101  r201 r302 r102  r202 , keep(EstablishedSpill VentureSpill     cumRD    preSample    ) order(EstablishedSpill VentureSpill          cumRD    preSample  )  cells(b(fmt(%9.1f) star) se(fmt(%9.1f) par)) starlevel(* 0.10 ** 0.05 *** 0.01) stats(fvalue r2 N, labels("F-Value"  "R2" "N") fmt(2 2 0))  label varlabels(_cons Constant)    level(90)  
* Start-ups
estout r311 r111  r211  r312 r112  r212   , keep(EstablishedSpill VentureSpill    AmountCum  preSample    ) order(EstablishedSpill VentureSpill      AmountCum  preSample    )  cells(b(fmt(%9.1f) star) se(fmt(%9.1f) par)) stats(fvalue r2 N, labels("F-Value"  "R2" "N") fmt(2 2 0))  label varlabels(_cons Constant)   level(90) 


}

**********************************************************************************************************************************************************************
* Table 6: Counterfactual increase in forward citation-weighted patents when spending 1 million dollars more on...
**********************************************************************************************************************************************************************

* Calculating the bootstrap over the external effects takes 100 hours on our computers, has 1000 lines of code and an interfers with the rest of the do file. 
* For that reason we do not include the code here. 
* I am happy to share the code and give instructions how to run it. Please email me: Martin.Watzinger@gmail.com.

* The following code shows the result of one iteration of the bootstrap mechanism. As a consequence the resulting numbers are not the mean numbers reported in the table but one observation within the confidence bounds.


* Code of one iterations

{
eststo clear



use work, clear

local i = 0
gen VentureSpill=0
gen EstablishedSpill = 0
gen IV1 = 0 
gen IV2 = 0
local direct cumRD

global exogenous      preSample dum_preSample    
forvalues k = 0/1 {
forvalues i = 1/4 {

di `i' " " `k'


if `i'==1 {
replace EstablishedSpill =  J_cumRD
replace VentureSpill = J_AmountCum
replace IV1 = J_cumRD_p
replace IV2 = J_AmountCum_p
}
else if `i'==2 {
replace EstablishedSpill =  C_cumRD
replace VentureSpill = C_AmountCum

replace IV1 = C_cumRD_p
replace IV2 = C_AmountCum_p
}
else if `i'==3 {
replace EstablishedSpill =  w12_cumRD
replace VentureSpill = w12_AmountCum
replace IV1 = w12_cumRD_p
replace IV2 = w12_AmountCum_p
}
else if `i'==4 {
replace EstablishedSpill =  C_cumRD
replace VentureSpill = C_AmountCumCorr
replace IV1 = C_cumRD_p
replace IV2 = C_AmountCumCorr_p
}


eststo r`i'`k'2: xi:  ivreg2  forwardCites_scaled i.SIC i.year   (VentureSpill EstablishedSpill =IV1 IV2 )    `direct'   $exogenous   if venture==`k' , cluster(SIC)   partial(i.SIC i.year) 
estadd scalar fvalue = e(F)
estadd local patentClass "Yes"
estadd local yearFix "Yes"

local direct`i'`k' = _b[`direct'] 
local VentureSpill`i'`k' = _b[VentureSpill]
local EstablishedSpill`i'`k' = _b[EstablishedSpill] 


} 
local direct AmountCum
global exogenous     preSample dum_preSample   
}

label var EstablishedSpill "Ln(Spillover Est.)" 
label var  VentureSpill "Ln(Spillover VC.)"







use work, clear


gen impact_Direct_VC = ((forwardCites_scaled_base+1)/(AmountCum_base+1)) if venture==1 & AmountCum_base>0

gen impact_Direct_VC_Corr = ((forwardCites_scaled_base+1)/(AmountCum_base+1)) if venture==1 & AmountCum_base>0

gen impact_Direct_RD = ((forwardCites_scaled_base+1)/(cumRD_base+1)) if venture==0 & cumRD_base>0
replace impact_Direct_VC= 0 if impact_Direct_VC==.
replace impact_Direct_RD= 0 if impact_Direct_VC==.
foreach x in J C {
gen impact_`x'_VC = ((forwardCites_scaled_base+1)/(`x'_AmountCum_base+1))*weightVenture`x'  if `x'_AmountCum_base>0
gen impact_`x'_Est = ((forwardCites_scaled_base+1)/(`x'_cumRD_base+1))*weightEst`x' if `x'_cumRD_base>0
replace impact_`x'_VC=0 if impact_`x'_VC==.
replace impact_`x'_Est =0 if impact_`x'_Est ==.
}
gen impact_C_VC_Corr = ((forwardCites_scaled_base+1)/(C_AmountCumCorr_base+1))*weightVentureC if C_AmountCumCorr_base>0
* Aufpassen ob Corr logarithmiert ist

foreach x in 12 {
gen  impact_Citation`x'_VC=((forwardCites_scaled_base+1)/(w`x'_AmountCum_base+1))*weight`x'Venture  if  w`x'_AmountCum_base>0
gen  impact_Citation`x'_Est=((forwardCites_scaled_base+1)/(w`x'_cumRD_base+1))*weight`x'Est if w`x'_cumRD_base>0
replace impact_Citation`x'_VC=0 if impact_Citation`x'_VC==.
replace impact_Citation`x'_Est=0 if impact_Citation`x'_Est==.
}






replace impact_Citation12_Est =  impact_Citation12_Est*`EstablishedSpill30' if venture==0
replace impact_Citation12_VC =  impact_Citation12_VC*`VentureSpill30' if venture==0
gen impact_Citation12_Direct_RD = impact_Direct_RD*`direct30' if venture==0
replace impact_Citation12_Direct_RD = . if venture==1


replace impact_J_Est =  impact_J_Est*`EstablishedSpill10' if venture==0
replace impact_J_VC =  impact_J_VC*`VentureSpill10' if venture==0
gen impact_J_Direct_RD = impact_Direct_RD*`direct10' if venture==0
replace impact_J_Direct_RD = .  if venture==1


replace impact_C_Est =  impact_C_Est*`EstablishedSpill20' if venture==0
replace impact_C_VC =  impact_C_VC*`VentureSpill20' if venture==0
gen impact_C_Direct_RD = impact_Direct_RD*`direct20'  if venture==0
replace impact_C_Direct_RD = . if venture==1

replace impact_C_VC_Corr =  impact_C_VC_Corr*`VentureSpill40' if venture==0



replace impact_Citation12_Est =  impact_Citation12_Est*`EstablishedSpill31' if venture==1
replace impact_Citation12_VC =  impact_Citation12_VC*`VentureSpill31'   if venture==1
gen impact_Citation12_Direct_VC=  impact_Direct_VC*`direct31' if venture==1
replace impact_Citation12_Direct_VC=  . if venture==0


replace impact_J_Est =  impact_J_Est*`EstablishedSpill11' if venture==1
replace impact_J_VC =  impact_J_VC*`VentureSpill11' if venture==1
gen impact_J_Direct_VC=  impact_Direct_VC*`direct11' if venture==1
replace impact_J_Direct_VC=  .  if venture==0

replace impact_C_Est =  impact_C_Est*`EstablishedSpill21' if venture==1
replace impact_C_VC =  impact_C_VC*`VentureSpill21' if venture==1
gen impact_C_Direct_VC=  impact_Direct_VC*`direct21' if venture==1
replace impact_C_Direct_VC= . if venture==0

replace impact_C_VC_Corr =  impact_C_VC_Corr*`VentureSpill41' if venture==1
gen impact_C_Direct_VC_Corr=  impact_Direct_VC_Corr*`direct41' if venture==1
replace impact_C_Direct_VC_Corr= . if venture==0


drop impact_Direct_VC impact_Direct_RD

collapse (mean) impact_J_Direct* impact_C_Direct* impact_Citation12_Direct* impact_J_V* impact_J_E* impact_C_E* impact_Citation12_E* impact_C_V* impact_Citation12_V*
local i = 0
foreach x in Citation12 J C  {
local i = `i'+1
ren  impact_`x'_VC impactVC`i'
ren  impact_`x'_Est impactEst`i'
ren impact_`x'_Direct_VC impactDirectVC`i'
ren impact_`x'_Direct_RD impactDirectRD`i'
}
gen impactEst4 = impactEst3
gen  impactDirectRD4 = impactDirectRD3 
ren impact_C_Direct_VC_Corr impactDirectVC4 
ren  impact_C_VC_Corr impactVC4 


gen i = _n
reshape long impactDirectRD impactDirectVC impactVC impactEst, i(i) j(model)
drop i
ren impactDirectVC impactDirect2
ren impactDirectRD impactDirect1
ren impactVC impact2
ren impactEst impact1
reshape long impactDirect impact, i(model) j(VC)
gen social = impactDirect+ impact
gen multiplier = 1
replace multiplier  = social/social[_n-1] if VC==2

gen multiplier_VCExt = 1
replace multiplier_VCExt  = impact/impact[_n-1] if VC==2

format VC impactDirect impact social multiplier %9.4f
label var impactDirect "Own company"
  
label define VC1 1 "R&D" 2 "VC"
label values VC VC1
label define model1 1 "Direct Citation" 2 "Jaffe" 3 "Citation Augmented" 4 "Corrected"
label values model model1

ren VC Sample
ren model Model
ren impactDirect Own
ren impact Other
ren social Total
ren multiplier Multiplier

list,   table 
}

}
